layui.use(['element','table','laytpl'],function () {
    var $ = layui.$,
        table = layui.table,
        layer = layui.layer;
    var tableIns = table.render({
        elem: '#demo'
        ,id:"mytable"
        ,url: '/settlement/list' //数据接口
        ,page: true //开启分页
        ,limit:15
        ,limits:[15,30,60,100]
        ,response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            ,statusCode: 200 //成功的状态码，默认：0
            ,msgName: 'msg' //状态信息的字段名称，默认：msg
            ,countName: 'total' //数据总数的字段名称，默认：count
            ,dataName: 'rows' //数据列表的字段名称，默认：data
        }
        ,cols: [[ //表头
            {type:'checkbox'}
            ,{title: '序号',type:'numbers'}
            // ,{field: 'code', title: '收费单编号',width:'15%'}
            ,{field: 'elderlyName', title: '老人姓名'}
            ,{field: 'elderlyIdNo', title: '身份证号'}
            ,{ title: '应收金额',templet:function(d){
                    return "￥ " + d.yingShou;
                }}
            ,{ title: '实收金额',templet:function(d){
                    d.yiShou = d.yiShou ? d.yiShou : 0;
                    return "￥ " + d.yiShou;
                }}
            ,{ title: '待收金额',templet:function(d){
                    d.yiShou = d.yiShou ? d.yiShou : 0;
                    return "￥ " + (d.yingShou - d.yiShou).toFixed(2);
                }}

            ,{ title: '状态',templet:function(d){
                    d.yiShou = d.yiShou ? d.yiShou : 0;
                    return (d.yingShou - d.yiShou) <= 0 ? '已付清' : '未付清';
             }}
            ,{title:'操作',toolbar:"#toolbar"}

        ]]
    });

    //工具条
    table.on("tool(test)",function(obj){
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        if("detail" == layEvent){
            location.href = "/settlement/detail?elderlyId=" + data.elderlyId+"&elderlyName="+data.elderlyName + "&elderlyIdNo=" + data.elderlyIdNo;
        }

    });

    /**
     * 搜索
     */
    $("#search").on('click',function(){
        var params = $("#search-form").serializeObject();
        tableIns.reload({
            where: params //设定异步数据接口的额外参数
        });
    });
    $("#reset").on('click',function(){
        tableIns.reload({
            where: {} //设定异步数据接口的额外参数
        });
    });

    /**
     * 搜索
     */
    $("#search").on('click',function(){
        var params = $("#search-form").serializeObject();
        tableIns.reload({
            where: params //设定异步数据接口的额外参数
        });
    });
    $("#reset").on('click',function(){
        tableIns.reload({
            where: {} //设定异步数据接口的额外参数
        });
    });

});